package com.zld.smarket.controller;

import com.zld.smarket.dto.TotalSaleData;
import com.zld.smarket.dto.TypeRate;
import com.zld.smarket.pojo.Goods;
import com.zld.smarket.pojo.Sale;
import com.zld.smarket.result.ExceptionMsg;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/sale")
public class SaleController {
    @Autowired
    private SaleService saleService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public ResponseData findList(Integer page, Integer limit){
        return  saleService.findList(page,limit);
    }

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseData search(String s,Integer page, Integer limit){
        return  saleService.search(s,page,limit);
    }


    @RequestMapping(value = "/add")
    public ResponseData add(Sale sale){
        Long i=sale.getSaleNo();
        if(saleService.selectbyno(i)>0){
            return new ResponseData(ExceptionMsg.ADDERROR);
        }else {
            sale.setSaleDate(new Date());
            Integer integer = saleService.addsale(sale);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }
    }
    @RequestMapping(value = "/weeksale")
    private List<TotalSaleData> weeksale(){
        return saleService.weeksale();
    }

    @RequestMapping(value = "/typerate")
    private List<TypeRate> typerate(){
        return saleService.typerate();
    }

    @RequestMapping(value = "/salenumrate")
    private List<TypeRate> salenumrate(){
        return saleService.salenumrate();
    }

    @RequestMapping(value = "/salenum")
    private List<Long> salenum(String s){
        if (s==null){ s="12";}
        return saleService.salenum(s);
    }

    @RequestMapping(value = "/weektotalsale")
    private TotalSaleData weektotalsale(){
        return saleService.weektotalsale();
    }

    @RequestMapping(value = "/monthtotalsale")
    private TotalSaleData monthtotalsale(){
        return saleService.monthtotalsale();
    }
}
